import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'IPTVOPlatform.settings')
django.setup()
from django.contrib.auth.hashers import make_password

from oplatform.models import User
from utils.encryption import cal_md5_string, cal_sha1_string


def clear_all():
    User.objects.all().delete()


def create_default_user():
    data = {
        'id': 1,
        'username': 'admin',
        'alias': '超级管理员',
        'password': make_password(cal_sha1_string(cal_md5_string('superadministrator'))),
    }
    super_admin = User.objects.create(**data)
    super_admin.save()


def run():
    clear_all()
    create_default_user()
    print('user created')


run()
